package com.lagou.pojo;

import lombok.Data;

import java.util.Calendar;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * Created by wangq on 2021/9/27.
 */
@Data
@Entity
@Table(name = "lagou_auth_code")
public class AuthCode {
    @Id
    private long id; // 主键

    private String email; // 邮箱

    private String code; // 验证码

    private Date createtime; // 创建时间

    private Date expiretime; // 过期时间

    public AuthCode() {
    }

    public AuthCode(String email, String code) {
        this.email = email;
        this.code = code;
        this.createtime = new Date();
        this.expiretime = calcExpiretime(createtime);
    }

    private Date calcExpiretime(Date createtime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(createtime);
        calendar.add(Calendar.MINUTE, 10);
        return calendar.getTime();
    }
}